package dji.ux.ext.setting.vps;

import androidx.annotation.NonNull;

import dji.keysdk.DJIKey;
import dji.keysdk.FlightControllerKey;
import dji.thirdparty.io.reactivex.Completable;
import dji.thirdparty.io.reactivex.Flowable;
import dji.ux.beta.base.DJISDKModel;
import dji.ux.beta.base.SchedulerProviderInterface;
import dji.ux.beta.base.WidgetModel;
import dji.ux.beta.base.uxsdkkeys.ObservableInMemoryKeyedStore;
import dji.ux.beta.util.DataProcessor;

public class ReturnVpsModel extends WidgetModel {
    private SchedulerProviderInterface schedulerProvider;
    private final DataProcessor<Boolean> returnVpsEnableProcessor;

    public ReturnVpsModel(@NonNull DJISDKModel djiSdkModel,
                        @NonNull ObservableInMemoryKeyedStore keyedStore,
                        @NonNull SchedulerProviderInterface scheduletProviderInterface) {
        super(djiSdkModel, keyedStore);
        this.schedulerProvider = scheduletProviderInterface;
        returnVpsEnableProcessor = DataProcessor.create(false);
    }

    public Flowable<Boolean> getReturnVpsEnabled() {
        return returnVpsEnableProcessor.toFlowable();
    }

    public Completable setEnable(boolean isChecked) {
        DJIKey returnVpsEnabledKey = FlightControllerKey.createFlightAssistantKey(FlightControllerKey.ACTIVE_OBSTACLE_AVOIDANCE_ENABLED);
        return djiSdkModel.setValue(returnVpsEnabledKey, isChecked).subscribeOn(schedulerProvider.io());
    }

    @Override
    protected void inSetup() {
        FlightControllerKey returnVpsEnabledKey =
                FlightControllerKey.createFlightAssistantKey(FlightControllerKey.ACTIVE_OBSTACLE_AVOIDANCE_ENABLED);
        bindDataProcessor(returnVpsEnabledKey, returnVpsEnableProcessor);
    }

    @Override
    protected void inCleanup() {

    }

    @Override
    protected void updateStates() {

    }
}
